function setCookie(key, val, day, path = "/") {

    if (day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = key + "=" + encodeURIComponent(val) + ";expires=" + date.toUTCString() + ";path=" + path;
    } else {
        document.cookie = key + "=" + encodeURIComponent(val) + ";path=" + path;
    }
}

function getCookie(key) {
    var cookie = document.cookie;
    if (cookie) {
        var list = cookie.split("; ");
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            var name = item.split("=")[0];
            var val = item.split("=")[1];
            if (name === key) {
                return decodeURIComponent(val);
            }

        }
    }
    return "";
}

function delCookie(key) {
    setCookie(key, "", -1);
}


function clearCookie() {
    var cookie = document.cookie;
    if (cookie) {
        var list = cookie.split("; ");
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            var key = item.split("=")[0];
            delCookie(key)
        }
    }
    return "";
}
